import java.util.*;

/**
 * @author LKQ
 * @date 2022/4/24 21:45
 * @description 前缀和
 */
public class Solution2 {
    public static void main(String[] args) {

    }
    public int numberOfSubarrays(int[] nums, int k) {
        int n = nums.length;
        int[] cnt = new int[n + 1];
        // odd奇数个数的前缀和
        int odd = 0, ans = 0;
        cnt[0] = 1;
        for (int i = 0; i < n; ++i) {
            odd += nums[i] & 1;
            ans += odd >= k ? cnt[odd - k] : 0;
            cnt[odd] += 1;
        }
        return ans;
    }

}
